package com.example.arithmeticleetcode.leetcode.September;

import java.util.*;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-09-24 14:33
 **/
public class Demo19 {

    public static void main(String[] args) {
        System.out.println(powerfulIntegers(2, 3, 10));
        System.out.println(powerfulIntegers(3, 5, 15));
    }

    public static List<Integer> powerfulIntegers(int x, int y, int bound) {
        if (bound < 2) {
            return new ArrayList<>();
        }
        int xIndex = 0;
        int xResult = 0;
        List<Integer> xList = new ArrayList<>();
        while (xResult < bound) {
            xResult = new Double(Math.pow(x, xIndex ++)).intValue();
            xList.add(xResult);
        }
        int yIndex = 0;
        int yResult = 0;
        List<Integer> yList = new ArrayList<>();
        while (yResult < bound) {
            yResult = new Double(Math.pow(y, yIndex ++)).intValue();
            yList.add(yResult);
        }
        List<Integer> list = new ArrayList<>();
        for (Integer i : xList) {
            for (Integer j : yList) {
                int sum = i + j;
                if (!list.contains(sum) && sum <= bound) {
                    list.add(sum);
                }
            }
        }
        return list;
    }
}
